package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairDataCalc;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.SentenceInfo;
import geppetto.reordering.graph.ReorderingGraph;
import geppetto.reordering.graph.scorers.NoDiscontinuousScorer;
import geppetto.reordering.graph.scorers.UnweightedGraphScorer;

public class SubPathsDataCalc implements ExtractedPhrasePairDataCalc{

	@Override
	public ExtractedPhrasePairData calcData(ExtractedPhrasePair epp) {
		SentenceInfo info = epp.getSentenceInfo();
		if(info.getCustomInfo("sub-phrase-graph") == null){
			info.setCustomInfo("sub-phrase-graph", getGraph(info));
		}
		return new SubPathsData(((ReorderingGraph)info.getCustomInfo("sub-phrase-graph")).getNumberOfPathsForIndexes(epp.getForeignStartPos(), epp.getForeignEndPos()));
	}

	@Override
	public ExtractedPhrasePairData loadFromString(String s) {
		return SubPathsData.parseString(s);
	}

	public ReorderingGraph getGraph(SentenceInfo senInfo){
		ReorderingGraph graph = new ReorderingGraph(senInfo);
		graph.setScorer(new NoDiscontinuousScorer());
		graph.generateWeightedGraphAllPaths();
		return graph;
	}
}
